package com.jms.utils;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class BinaryFile {

	public static String read(String filePath) throws Exception {  
        StringBuffer sb=new StringBuffer();
        FileInputStream fis = new FileInputStream(filePath);

        InputStreamReader Inputreader = new InputStreamReader(fis,"utf-8");
        BufferedReader br = new BufferedReader(Inputreader);  
        String temp=br.readLine();
        StringBuffer data=new StringBuffer();
        while(temp!=null){
        	  temp+='\n';
              data.append(temp); //接着读下一行
              temp=br.readLine();
        }
        
        return data.toString();  
    }  
  
    // 把字节数组为写入二进制文件，数组为null时直接返回  
    public static void write(String filePath, byte[] data) {  
        if (data == null)  
            return;  
        try {  
            BufferedOutputStream out = new BufferedOutputStream(  
                    new FileOutputStream(filePath));  
            try {  
                out.write(data);  
            } finally {  
                out.close();  
            }  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    } 
}
